﻿using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using Kingdee.BOS.Core;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Util;
using Kingdee.K3.Core.MFG.EntityHelper;
using Kingdee.K3.Core.MFG.EnumConst;

namespace Caraya.MFG.BusinessPlugIn
{
    /// <summary>
    /// 单据转换插件
    /// </summary>
    [Description("生产汇报入库转换插件"), HotUpdate]
    public class InStockConvertPlugIn : Kingdee.BOS.Core.Metadata.ConvertElement.PlugIn.AbstractConvertPlugIn
    {
        public override void AfterConvert(Kingdee.BOS.Core.Metadata.ConvertElement.PlugIn.Args.AfterConvertEventArgs e)
        {
            base.AfterConvert(e);

            //下推单据只保留合格品
            ExtendedDataEntity[] objs = e.Result.FindByEntityKey("FBillHead"); //获取单据数据包 FBillHead是单据头标知
            foreach (ExtendedDataEntity obj in objs)
            {
                //找到生产入库单的表体数据
                DynamicObjectCollection entryDatas = obj.DataEntity.GetDynamicValue<DynamicObjectCollection>(Consts_PRD_InStock.Orm_Entry_Entity);
                List<DynamicObject> wEntryDatas = entryDatas.Where(w => w.GetDynamicValue<string>(Consts_PRD_InStock.Orm_Entry_InStockType) != "1").ToList();//找到入库单表体分录入库类型不是合格品入库数据
                foreach (DynamicObject entryData in wEntryDatas)
                {
                    //循环移除掉
                    entryDatas.Remove(entryData);
                }

            }
        }
    }
}
